<?php
class tbdata_api_b2c extends tbdata_api_request{

    var $app_secret = 'c7d4c1924b383385ecdc0d0e87c46c1b0bd6174c8b3a62711657619dde5cd5ec';
    var $api_url = 'http://127.0.0.1/shop485/api.php';

    public function get_brand_list(){
        $params = $this->system_static_params();
        $params['act'] = 'get_brand';
        $params['ac'] = $this->gen_sign($params);

        return $this->request($params);
    }
    public function get_products_list($params){
        $params = $this->system_static_params()+$params;
        $params['act'] = 'get_products_list';
        $params['ac'] = $this->gen_sign($params);

        return $this->request($params);
    }
    public function get_brand_single($brand_id){
        $params = $this->system_static_params();
        $params['act'] = 'get_brand_single';
        $params['brand_id'] = $brand_id;
        $params['ac'] = $this->gen_sign($params);

        return $this->request($params);
    }

    public function get_classification($brand_id){
        $params = $this->system_static_params();
        $params['act'] = 'get_classification';
        $params['ac'] = $this->gen_sign($params);
        
        return $this->request($params);
    }
    
    public function get_classification_single($cid){
        $params = $this->system_static_params();
        $params['act'] = 'get_classification_single';
        $params['cat_id'] = $cid;
        $params['ac'] = $this->gen_sign($params);

        return $this->request($params);
    }

    public function get_category($cid){
        $params = $this->system_static_params();
        $params['act'] = 'get_category';
        $params['ac'] = $this->gen_sign($params);

        return $this->request($params);
    }

    public function get_category_single($cid){
        $params = $this->system_static_params();
        $params['act'] = 'get_category_single';
        $params['type_id'] = $cid;
        $params['ac'] = $this->gen_sign($params);

        return $this->request($params);
    }
    public function get_spec($cid){
        $params = $this->system_static_params();
        $params['act'] = 'get_spec';
        $params['type_id'] = $cid;
        $params['ac'] = $this->gen_sign($params);

        return $this->request($params);
    }
    public function get_spec_single($spec_id){
        $params = $this->system_static_params();
        $params['act'] = 'get_spec_single';
        $params['spec_id'] = $spec_id;
        $params['ac'] = $this->gen_sign($params);

        return $this->request($params);
    }
    public function get_spec_value($spec_id){
        $params = $this->system_static_params();
        $params['act'] = 'get_spec_value';
        $params['spec_id'] = $spec_id;
        $params['ac'] = $this->gen_sign($params);

        return $this->request($params);
    }

    public function gen_sign($params){
        ksort($params);
        $tmp_verfy = '';
        foreach($params as $key=>$value){
            $params[$key] = stripslashes($value);
            $tmp_verfy .= $params[$key];
        }
        $s_key = $tmp_verfy;
        return strtolower(md5(trim($tmp_verfy.$this->app_secret)));
    }
    public function system_static_params(){
        $params['api_version'] = '1.0';
        #$params['last_modify_st_time'] = time()-3600*24*3100;
        #$params['last_modify_en_time'] = time();
        #$params['counts'] = 20;
        $params['return_data'] = 'json';
        return $params;
    }
}